<%@page pageEncoding="UTF-8" %>
<!doctype html>
<html lang="zh-cmn">
<head>
    <title>Document</title>
    <%@include file="/WEB-INF/jsp/header.jsp"%>
    <style>
        .yi th{
            text-align: center;
        }
    </style>
</head>
<body>
<div class="container-fluid">
    <div style="margin: auto;width: 80%">
        <table class="table table-bordered" style="margin-top: 16px;">
            <tr>
                <td colspan="2" class="text-center h4">盘点基本信息</td>
            </tr>
            <tr>
                <td><label >盘点单号：</label><span>${inventorying.invNum}</span></td>
                <td><label >盘点人员：</label><span>${inventorying.invPers}</span></td>
            </tr>
            <tr>
                <fmt:formatDate value="${inventorying.invDate}" pattern="yyyy-MM-dd" var="d"></fmt:formatDate>
                <td><label >盘点时间：</label><span>${d}</span></td>
                <td><label >审查人员：</label><span>${inventorying.invAuditper}</span></td>
            </tr>
        </table>
        <div style="height: 20px;background: 	#FFF5EE;opacity: 0.3" >

        </div>
        <table style="margin-top: 10px" class="table table-bordered">
            <thead>
                <tr class="yi">
                    <th colspan="5">药品信息</th>
                    <th colspan="2">账面情况</th>
                    <th colspan="2">实盘情况</th>
                    <th colspan="2">盘盈</th>
                    <th colspan="2">盘亏</th>
                </tr>
                <tr>
                    <th>
                        药品名称
                    </th>
                    <th>
                        药品价格
                    </th>
                    <th>
                        药品单位
                    </th>
                    <th>
                        药品规格
                    </th>
                    <th>
                        批号
                    </th>
                    <th>
                        数量
                    </th>
                    <th>
                        金额
                    </th>
                    <th>
                        数量
                    </th>
                    <th>
                        金额
                    </th>
                    <th>
                        数量
                    </th>
                    <th>
                        金额
                    </th>
                    <th>
                        数量
                    </th>
                    <th>
                        金额
                    </th>
                </tr>
            </thead>
            <tbody>
                <c:forEach items="${list}" var="v">
                    <tr>
                        <td>${v.druginfo.drugName}</td>
                        <td>${v.drugstock.stoPrimecost}</td>
                        <td>${v.druginfo.drugUnit}</td>
                        <td>${v.druginfo.drugStandard}</td>
                        <td>${v.drugstock.stoLotnum}</td>
                        <td>${v.indStock}</td>
                        <td><fmt:formatNumber type="number" var="d" value="${v.drugstock.stoPrimecost*v.indStock}" pattern="0.00" maxFractionDigits="2"/>${d}</td>
                        <td>${v.indAcstock}</td>
                        <td><fmt:formatNumber type="number" value="${v.drugstock.stoPrimecost*v.indAcstock}" pattern="0.00" maxFractionDigits="2"/></td>
                        <c:if test="${v.indAcstock>v.indStock}" var="flag">
                            <td>${v.indAcstock-v.indStock}</td>
                            <td class="ying"><fmt:formatNumber type="number" value="${(v.indAcstock-v.indStock)*v.drugstock.stoPrimecost}" pattern="0.00" maxFractionDigits="2"/></td>
                            <td></td>
                            <td></td>
                        </c:if>
                        <c:if test="${not flag}">
                            <td></td>
                            <td></td>
                            <td>${v.indStock-v.indAcstock}</td>
                            <td class="kui"><fmt:formatNumber type="number" value="${(v.indStock-v.indAcstock)*v.drugstock.stoPrimecost}" pattern="0.00" maxFractionDigits="2"/></td>
                        </c:if>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
        <div>
            <span style="font-weight: 800">合计:</span>
            <div style="margin-left: 50px;">盘盈:<span id="panying" style="font-weight: bold"></span></div>
            <div style="margin-left: 50px;">盘亏:<span id="pankui" style="font-weight: bold"></span>
                <c:if test="${inventorying.invState==0}" var="ff">
                    <div class="correction" style="float: right">
                        <button onclick="correction()" type="button" class="btn btn-info" >一键校正</button>
                    </div>
                </c:if>
                <c:if test="${not ff}">
                    <div class="correction2" style="float: right">
                        <h3>已校正</h3>
                    </div>
                </c:if>
            </div>
        </div>
    </div>
</div>
<%@include file="/WEB-INF/jsp/footer.jsp"%>
<script>
    var kui = $(".kui");
    var ying = $(".ying")
    var pankui = 0.00;
    var panying = 0.00;
    if(ying.length>1){

        for (var i = 0 ;i < ying.length;i++){
            panying+=parseInt(ying[i].innerHTML==''?0:ying[i].innerHTML);
        }

    }else{
        panying+=parseInt($(ying).html())
    }
    if(kui.length>1){
        for (var y = 0 ;y < kui.length;y++){
            pankui+=parseInt(kui[y].innerHTML==''?0:kui[y].innerHTML);
        }
    }else{
        pankui+=parseInt($(kui).html())
    }
    console.log("盘亏:"+pankui)
    $("#panying").html(panying)
    $("#pankui").html(pankui)

    function correction() {
        var invNum = '${inventorying.invNum}';
        location.href=ctx+"/stock/correctionDrugstock?invNum="+invNum;
    }

</script>
</body>
</html>
